package Ali;

import java.util.*;

public class Main_0915_2 {

    static Map<Integer,List<Integer>> graph;
    static long res=0;
    static boolean[] visited;
    public static void backtrack(int cur){
        for (int nextNode:graph.get(cur)) {
            if (visited[nextNode]){
                continue;
            }
            visited[nextNode]=true;
            backtrack(nextNode);
            res+=(nextNode-cur);
        }
    }
    public static void main(String[] args) {
        Scanner cin=new Scanner(System.in);
        int n=cin.nextInt();
        graph=new HashMap<>();
        for (int i = 1; i <=n ; i++) {
            graph.put(i,new LinkedList<>());
        }
        for (int i = 0; i < n - 1; i++) {
            int node1=cin.nextInt();
            int node2=cin.nextInt();
            graph.get(node1).add(node2);
            graph.get(node2).add(node1);
        }
        visited=new boolean[n+1];
        visited[1]=true;
        backtrack(1);
        System.out.println(res);
    }
}
